<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','telephone',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


    protected $table = 'users';

    protected $casts = [
            'address' => 'json',
            'industry'=>'json'
    ];

    public function collects()
    {
        return $this->belongsToMany(File::class, 'user_collects');
    }

    public function bought()
    {
        return $this->hasMany(DownloadRecord::class, 'user_id', 'id');
    }

    //设置手机号码
    public function setTelephone($mobile)
    {
        $this->attributes['telephone'] = $mobile;
    }
    
    //获取手机号码
    public function getTelephone()
    {
        return $this->telephone;
    }
    
    //设置性别
    public function setGender($gender)
    {
        $this->attributes['gender'] = $gender;
    }
    
    //获取性别
    public function getGender()
    {
        return $this->gender;
    }
    
    //设置地区
    public function setAddress($address)
    {
        if (is_array($address)) 
        {
            $this->attributes['address'] = json_encode($address);
        }
    }
    
    //获取地区
    public function getAddress()
    {
        return $this->address;
    }
    
    //设置行业
    public function setIndustry($industry)
    {
        if (is_array($industry))
        {
            $this->attributes['industry'] = json_encode($industry);
        }
    }
    
    //获取行业
    public function getIndustry()
    {
        return $this->industry;
    }
}
